package com.seckill.controller;

import com.seckill.pojo.dto.UserLoginInfo;
import com.seckill.service.UserLoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: hualao
 * @Version: 0.0.1V
 * @Date: 2019/1/11
 * @Description:
 **/
@RestController
public class UserLoginInfoController {

    @Autowired
    private UserLoginInfoService userLoginInfoService;

    /**
     * 新增用户登录记录到mongodb
     * @param info
     * @return
     */
    @PostMapping("add")
    public UserLoginInfo add(@RequestBody UserLoginInfo info) {
        return userLoginInfoService.saveUserLoginInfo(info);
    }


    /**
     * 根据用户id查询数据
     * @param userId
     * @return
     */
    @GetMapping("find/{userId}")
    public UserLoginInfo findUserLoginInfoUserId(@PathVariable Integer userId) {
        return userLoginInfoService.findUserLoginInfoUserId(userId);
    }

    /**
     * 根据mongodb id删除记录
     * @param id
     * @return
     */
    @GetMapping("del/{id}")
    public UserLoginInfo delUserLoginInfoById(@PathVariable String id) {
        return userLoginInfoService.delUserLoginInfoById(id);
    }

    /**
     * 根据mongodb id修改用户名
     * @param id
     * @return
     */
    @GetMapping("update/{id}/{username}")
    public Long updateUserLoginInfoById(@PathVariable String id, @PathVariable String username) {
        return userLoginInfoService.updateUserLoginInfoById(id, username);
    }

}
